<?php

/**
 * This is the model class for table "paciente".
 *
 * The followings are the available columns in table 'paciente':
 * @property integer $idPaciente
 * @property string $apellido
 * @property string $nombre
 * @property string $tipoDocumento
 * @property integer $nroDocumento
 * @property integer $idObraSocial
 * @property string $telefono
 * @property string $fechaNacimiento
 * @property integer $sexoMasculino
 */
class Paciente extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Paciente the static model class
	 */
	public $idEstudioPaciente;
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'paciente';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nroDocumento, idObraSocial, sexoMasculino', 'numerical', 'integerOnly'=>true),
			array('apellido, nombre, tipoDocumento, telefono', 'length', 'max'=>255),
				array('apellido, nombre, tipoDocumento, telefono', 'required'),
			array('fechaNacimiento, idEstudioPacienteIngreso, idEstudioPacientEgreso', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idPaciente, apellido, nombre, tipoDocumento, nroDocumento, idObraSocial, telefono, fechaNacimiento, sexoMasculino', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idPaciente' => 'Id Paciente',
			'apellido' => 'Apellido',
			'nombre' => 'Nombre',
			'tipoDocumento' => 'Tipo Documento',
			'nroDocumento' => 'Nro Documento',
			'idObraSocial' => 'Obra Social',
			'telefono' => 'Telefono',
			'fechaNacimiento' => 'Fecha Nacimiento',
			'sexoMasculino' => 'Sexo Masculino',
		);
	}
	
	public  function getTipoDocs(){
		
		return array('DNI', 'LC', 'LE', 'OTRO');
		
	}
	
	public function getObrasSociales(){
		
		$obraSocialModel=Obrasocial::model();
		$obrasSociales =$obraSocialModel->findAll(); 
		$names= array();
		foreach ($obrasSociales as $key	=> $obrasocial){
			array_push($names,$obrasocial->razonSocial );
		}
		return $names;
	}
	
	public function getFullName(){
		return  $this->nombre . ' ' . $this->apellido;
	}
	
	public function getNombreObraSocial(){
		$obraSocial = Obrasocial::model()->findByAttributes(array('idObraSocial'=>$this->idObraSocial)); 
		return $obraSocial->razonSocial;
		
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idPaciente',$this->idPaciente);
		$criteria->compare('apellido',$this->apellido,true);
		$criteria->compare('nombre',$this->nombre,true);
		$criteria->compare('tipoDocumento',$this->tipoDocumento,true);
		$criteria->compare('nroDocumento',$this->nroDocumento);
		$criteria->compare('idObraSocial',$this->idObraSocial);
		$criteria->compare('telefono',$this->telefono,true);
		$criteria->compare('fechaNacimiento',$this->fechaNacimiento,true);
		$criteria->compare('sexoMasculino',$this->sexoMasculino);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}